import { defineStore } from "pinia";
import { CatalogState } from "@/stores/interface";
import piniaPersistConfig from "@/config/piniaPersist";

export const useCatalogStore = defineStore({
  id: "catalog",
  state: (): CatalogState => ({
    treeNode: {}, // 点击左侧树节点保存对象
    catalogList: [], // 左侧树平级数据
    sourthCatalogList: [] // 左侧树平级源数据
  }),
  getters: {
    getCatalogList(state) {
      return state.catalogList;
    }
  },
  actions: {
    // 获取点击分类节点
    SetTreeNode(data: any) {
      this.treeNode = data;
    },
    // 保存树节点数据
    setCatalogList(list: any) {
      this.catalogList = list;
    },
    // 保存源树节点数据
    setSourthCatalogList(list: any) {
      this.sourthCatalogList = list;
    }
  },
  persist: piniaPersistConfig("catalog", ["treeNode"])
});
